package cate.game.pvp.throne.data.ko;

import cate.common.table.d.GDThrone;
import cate.game.pvp.throne.data.TBGroupData;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;

public class TBKoData extends TBGroupData {

	public static final String COLLECTION = "tb-ko";

	@NoteField("分组赛数据")
	public TBKoDivide divide;

	@NoteField("晋级赛数据")
	public TBKoAdvance advance;

	@NoteField("冠军对决数据")
	public TBKoChampion champion;

	@Override
	public void init() {
		if (divide == null) {
			divide = new TBKoDivide();
		}
		divide.initialize();
		if (advance == null) {
			advance = new TBKoAdvance();
		}
		advance.initialize();
		if (champion == null) {
			champion = new TBKoChampion();
		}
		champion.initialize();
	}

	public void clear(){
		divide.clear();
		advance.clear();
		champion.clear();
	}


	public TBKoMatch findBetMatch(TBKoCurBet curBet) {
		if (curBet == null) {
			return null;
		}
		switch (curBet.gameType) {
			case GDThrone.KoGameType.DIVIDE:
				return divide.findMatch(curBet.matchGroup);
			case GDThrone.KoGameType.ADVANCE:
				return advance.findMatch(GDThrone.KoGroupType.WINNER, curBet.round, curBet.matchGroup);
			case GDThrone.KoGameType.CHAMPION:
				return champion.findMatch();
			default:
				return null;
		}
	}

	public List<TBKoReport> findRoleReports(String roleUid){
		List<TBKoReport> results = new ArrayList<>();
		results.addAll(divide.findRoleReports(roleUid));
		results.addAll(advance.findRoleReports(roleUid));
		results.addAll(champion.findRoleReports(roleUid));
		return results;
	}
}
